﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

namespace Mall
{
    public partial class NewsCenter : System.Web.UI.Page
    {
       public System.Data.DataTable dt = new DataTable();
       public string id = string.Empty;
       public string action = string.Empty;
       public string pagesize = string.Empty;
       public string start = string.Empty;
       public string fiter = string.Empty;
       public string countt = string.Empty;
       public string page = string.Empty;
       public string keyword = string.Empty;
       public string html_str_newsmcview_left_hot = string.Empty;
       public string html_str_newsmcview_left_new = string.Empty;
       public string html_str_newsmcview_left_his = string.Empty;
            
        protected void Page_Load(object sender, EventArgs e)
        {
             id = Request["id"] == null ? string.Empty : Request["id"].ToString();
             action = Request["action"] == null ? string.Empty : Request["action"].ToString();
             pagesize = "10";
             start = "0";
             fiter = "";
             countt = "0";//总条数
             page = "0";//当前页码
            page = Request["page"] == null ? "1" : Request["page"].ToString();
            string keyword = Request["keyword"] == null ? string.Empty : Request["keyword"].ToString();
            BLL.Models.MClassModels model_class = new BLL.Models.MClassModels();
            start = Convert.ToString(Convert.ToInt32(page) * Convert.ToInt32(pagesize));
            if (page == "1")
            {

                start = "0";
            }

            ///查询分类
            if (!string.IsNullOrEmpty(id))
            {

                fiter = fiter + " and classid in (" + model_class.GetIdList(id) + ") ";

            }
            if (!string.IsNullOrEmpty(keyword))
            {

                fiter = fiter + " and productname like '%" + keyword + "%' ";
            }
            //排序
            switch (action)
            {
                case "new":
                    fiter = fiter + "order by id desc";
                    break;
                case "hot":
                    fiter = fiter + "order by buycount desc";
                    break;
                case "tejia":
                    fiter = fiter + "order by price asc";
                    break;
                default:
                    break;
            }
           
            string pagecount = "0";
            pagecount = Convert.ToInt32(countt) % Convert.ToInt32(pagesize) == 0 ? (Convert.ToInt32(countt) / Convert.ToInt32(pagesize)).ToString() : (Convert.ToInt32(countt) / Convert.ToInt32(pagesize)) < 1 ? "1" : (Convert.ToInt32(countt) / Convert.ToInt32(pagesize) + 1).ToString();
            //TempData["counttnew"] = countt;
            //TempData["idnew"] = id;
            //TempData["actionnew"] = action;
            //TempData["pagenew"] = page;
            //TempData["pagesizenew"] = pagesize;
            //TempData["pagecountnew"] = pagecount;
            //TempData["keywordnew"] = keyword;
            string lastview = Request.Cookies["lastview"] == null ? "" : Request.Cookies["lastview"].ToString();
            BLL.Models.MArticleModels model = new BLL.Models.MArticleModels();
            BLL.Models.ProductModels models_product = new BLL.Models.ProductModels();
            string html_str_newsmcview_left_hot = models_product.GetProductHotLeft(7);
            string html_str_newsmcview_left_new = models_product.GetProductnewLeft(7);
            string html_str_newsmcview_left_his = models_product.GetProductHisLeft(7, lastview);
            dt = model.GetArticleAll(start, ref countt, fiter, pagesize);
            //ViewData["newsmcvires"] = dt;
            //ViewData["html_str_newsmcview_left_hot"] = html_str_newsmcview_left_hot;
            //ViewData["html_str_newsmcview_left_new"] = html_str_newsmcview_left_new;
            //ViewData["html_str_newsmcview_left_his"] = html_str_newsmcview_left_his;

        }
    }
}